package com.weeasy.location.controller;

import com.weeasy.core.common.Result;
import com.weeasy.location.service.LocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 微信位置控制器
 * 
 * @author we-easy
 * @since 1.0.0
 */
@RestController
@RequestMapping("/location")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class LocationController {

    private final LocationService locationService;

    /**
     * 获取位置信息
     * 
     * @return 位置信息
     */
    @GetMapping("/info")
    public Result<String> getLocationInfo() {
        String location = locationService.getLocationInfo();
        return Result.success("获取位置信息成功", location);
    }

    /**
     * 更新位置信息
     * 
     * @param latitude 纬度
     * @param longitude 经度
     * @param address 地址
     * @return 更新结果
     */
    @PostMapping("/update")
    public Result<String> updateLocation(@RequestParam Double latitude, 
                                       @RequestParam Double longitude, 
                                       @RequestParam String address) {
        String result = locationService.updateLocation(latitude, longitude, address);
        return Result.success("更新位置信息成功", result);
    }
}
